import 'package:flutter/material.dart';

class LifeCase extends StatefulWidget {
  const LifeCase({Key? key}) : super(key: key);

  @override
  _LifeCaseState createState() {
    print("1.createState执行");
    return _LifeCaseState();
  }
}

class _LifeCaseState extends State<LifeCase> {
  int count = 0;

  @override
  void initState() {
    // TODO: implement initState
    super.initState(); // 必须调用
    print('2.initState'); // 在这里做数据请求
  }

  @override
  void didChangeDependencies() {
    // TODO: implement didChangeDependencies
    super.didChangeDependencies();
    print('3.didChangeDependencies'); // 在这里做数据请求
  }

  @override
  void didUpdateWidget(covariant LifeCase oldWidget) {
    // TODO: implement didUpdateWidget
    super.didUpdateWidget(oldWidget);
    print('5.didUpdateWidget');
  }

  @override
  Widget build(BuildContext context) {
    print('4.执行build函数');
    return Row(
      children: [
        ElevatedButton(
            onPressed: () {
              setState(() {
                count--;
              });
            },
            child: const Text("-")),
        Text(count.toString()),
        ElevatedButton(
            onPressed: () {
              setState(() {
                count++;
              });
            },
            child: const Text("+"))
      ],
    );
  }
}
